package com.bdqn.t330.controller;


import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

//DemoController demoController = new DemoController();

@Controller
@RequestMapping("/hello")
public class DemoController {

    //可以用get或者post或者其它形式的请求
    @RequestMapping(name = "sadfdsafsdaf", value = {"/demo", "/demo1"}, method = RequestMethod.GET)
    public String demo(Model model, @RequestParam(required = false) String uname) {
        System.out.println("uname:" + uname);
        model.addAttribute("uname", "姓名:" + uname);
        return "/demo";
    }

    //转发语法  return "/demo";
    //转发是发生在服务器内部，所以他才能访问web-inf里面的资源,url不会变化
    //转发能够携带request请求中的数据

    //重定向语法 return "redirect:/demo";
    //重定向 url会变化,是作用在客户端上发送的请求 js中也只有重定向location.href='',
    //重定向是能跳转到指定的页面(www.baidu.com),类似于直接在浏览器上输入一个url
    //重定向是能从controller跳转到controller
    //重定向能通过?的形式携带数据


    @RequestMapping("/demo2")
    public String demo2(Model model, @RequestParam String uname) {
        System.out.println("uname:" + uname);
        model.addAttribute("uname", "我的姓名是:" + uname);
        return "/demo";
    }


    @RequestMapping("/demo3")
    public String demo3() {
        System.out.println("demo3....");
        return "redirect:http://www.baidu.com";
        //return "redirect:/demo";
    }


    //只需允许get请求
    //@GetMapping

    //只需允许post请求
    //@PostMapping
}
